package ext.sim.forces;

import ext.sim.Body;
import java.util.ArrayList;
import math.vec3;
import static math.vec3.mul;
import static math.vec3.norm;
import static math.vec3.proj;
import static math.vec3.sub;

/** Attractive force that pulls all bodies towards a plane with 
    directions only along the lines perpendicular to the plane. */
public class ForceVortexPlanar implements Force
{
    
    private ArrayList<Body> rBodies;
    
    private vec3 mPoint;
    
    private vec3 mNormal;
    
    private double mStrength;
    
    
    public ForceVortexPlanar(
            ArrayList<Body> aBodies, 
            vec3 aPoint, 
            vec3 aNormal, 
            double aStrength)
    {
        this.rBodies = aBodies;
        this.mPoint = aPoint;
        this.mNormal = norm(aNormal);
        this.mStrength = aStrength;
    }
    
    
    public void apply()
    {
        for (Body b : this.rBodies)
        {
            vec3 toX = sub(b.mX, this.mPoint);
            vec3 axisProj = proj(toX, this.mNormal);
            
            vec3 fPlanar = mul(-this.mStrength, axisProj);
            
            b.mF.add(fPlanar);
        }
    }
    
}
